var e = require("../../../@babel/runtime/helpers/interopRequireDefault"), t = e(require("../../../@babel/runtime/regenerator")), r = require("../../../@babel/runtime/helpers/asyncToGenerator"), a = e(require("../../../http/address")), n = require("../../../utils/tool"), s = getApp(), o = require("../../../http/activityApi.js"), u = require("../../../http/indexApi.js"), c = new a.default();

Component({
    options: {
        addGlobalClass: !0
    },
    properties: {
        show: Boolean,
        data: Object
    },
    data: {},
    methods: {
        payOnConfirm: function() {
            var e = this;
            return r(t.default.mark(function r() {
                var a, u, d, i;
                return t.default.wrap(function(t) {
                    for (;;) switch (t.prev = t.next) {
                      case 0:
                        return t.prev = 0, s.showLoading(), t.next = 4, c.getDefaultAddress();

                      case 4:
                        if (a = t.sent, u = a.data.addressId) {
                            t.next = 9;
                            break;
                        }
                        return e.getCurrentPage().selectComponent("#deliver").showPopup(), t.abrupt("return");

                      case 9:
                        return t.next = 11, o.superCouponOrderCreate({
                            addressId: u,
                            usedId: e.data.data.usedId,
                            superCouponsProductId: e.data.data.id
                        });

                      case 11:
                        if (a = t.sent, e.orderId = a.data.orderId, e.data.data.amount != e.data.data.discountAmount) {
                            t.next = 18;
                            break;
                        }
                        return t.next = 16, o.superCouponOrderPayZero(e.orderId);

                      case 16:
                        return e.paySuccess(), t.abrupt("return");

                      case 18:
                        return t.next = 20, (0, n.promising)(wx.login)();

                      case 20:
                        return d = t.sent, t.next = 23, o.superCouponOrderPay(d.code, e.orderId);

                      case 23:
                        a = t.sent, (i = a.data.miniPayRequest).success = function(t) {
                            console.log("【支付成功】", t), e.paySuccess();
                        }, i.fail = function(t) {
                            console.log("【支付失败】", t), e.cancelOrder();
                        }, wx.requestPayment(i), t.next = 33;
                        break;

                      case 30:
                        t.prev = 30, t.t0 = t.catch(0), console.log(t.t0);

                      case 33:
                        return t.prev = 33, wx.hideLoading(), t.finish(33);

                      case 36:
                      case "end":
                        return t.stop();
                    }
                }, r, null, [ [ 0, 30, 33, 36 ] ]);
            }))();
        },
        paySuccess: function() {
            var e = this;
            wx.requestSubscribeMessage({
                tmplIds: [ "vBPr22DDXOhYMu7o3hc3k055YKUvYSmncOQjkcVzLE0", "hdkwX1PFKY08Wrw3z18S6oFpn2SeoyToVW4qGW2L-4w", "C1t5mpxs6FRapLx2Ht1gnmwpDyKwJj1HkEzWJ_mv6R0" ],
                success: function(t) {
                    u.subscribeNotice({
                        messageType: 7,
                        messageId: e.orderId
                    }).then(function(e) {}).catch(function(e) {});
                },
                fail: function(e) {
                    console.log(e);
                }
            }), this.setData({
                show: !1
            });
            var t = this.getCurrentPage();
            t.setData({
                showPaySuccess: !0
            }), t.onPaySuccess ? t.onPaySuccess() : t.loadDetails && t.loadDetails();
        },
        cancelOrder: function() {
            s.showToast("取消支付"), o.superCouponOrderCancel(this.orderId).then(function(e) {
                console.log("【取消订单】", e);
            }).catch(function(e) {});
        },
        getCurrentPage: function() {
            var e = getCurrentPages();
            return e[e.length - 1];
        }
    }
});